<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class AdminGoodsAddRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
        'gname'=>'required',
        'price'=>'required|regex:/\d+/',
        'cnt'=>'required',
        'dcont'=>'regex:/^\d{1,2}\.[0-9]$/',
        'gsize'=>'required',
        ];
    }
    //验证方法  获取已定义验证规则的错误消息。
    public function messages()
    {
        return [
            'gname.required' => '商品名不能为空',
            'price.required' => '价格不能为空',
            'cnt.required' => '库存不能为空',
            'gsize.required' => '尺寸不能为空',
            'price.regex'  => '价格必须为数字',
            'dcont.regex'  => '折扣格式不正确',
        ];
    }
}
